<template>
        <el-card shadow="never" style="max-height: 70vh; overflow: auto">
            <el-form ref="form" :model="form" :rules="rules" label-width="120px" :disabled="disabled">
                <el-form-item label="id:" prop="id" v-show="false">
                    <el-input v-model="form.id" disabled />
                </el-form-item>
                <el-form-item label="所属专家:" prop="spec_id">
                    <SelectPage v-model="form.spec_id" :url="'/admin/sq.specialist/selectPage'" show_field="realname" show_id="id" placeholder="请选择专家"
                                query_field="id" :multiple="false" />
                </el-form-item>
                <el-form-item label="推广类型:" prop="promotion_type">
                    <el-radio-group v-model="form.promotion_type">
                        <el-radio v-for="(item, index) in promotion_type" :key="index" :label="item.value">{{ item.label }}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="状态:" prop="status">
                    <el-radio-group v-model="form.status">
                        <el-radio v-for="(item, index) in status" :key="index" :label="item.value">{{ item.label }}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="结束类型:" prop="end_type">
                    <el-radio-group v-model="form.end_type">
                        <el-radio v-for="(item, index) in end_type" :key="index" :label="item.value">{{ item.label }}</el-radio>
                    </el-radio-group>
                </el-form-item>
                <el-form-item label="推广结束时间:" prop="end_time" v-if="form.end_type === 1">
                    <el-date-picker v-model="form.end_time" type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择推广结束时间" :pickerOptions="pickerOptions" />
                </el-form-item>
                <el-form-item label="排序:" prop="sortweight">
                    <el-input-number v-model="form.sortweight" :step="1" :min="0"></el-input-number>
                    <div>越小越靠前</div>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm">确认 </el-button>
                    <el-button type="warning" @click="cancel">取消 </el-button>
                </el-form-item>
            </el-form>
        </el-card>
</template>

<script>
import { regionData } from 'element-china-area-data'

export default {
    name: 'EditForm',
    props: {
        findFormData: {
            type: Object,
            default: {}
        },
        editFormParams: {
            type: Object,
            default: {}
        },
        // 表单是否禁用
        disabled: {
            type: Boolean,
            default: false,
        },
    },
    data() {
        return {
            // 编辑表单验证规则
            rules: {},
            form: {  },
            // 区域选择配置
            areaOptions: regionData,
            promotion_type:[
               { label: "限时推广", value: 1 },
            ],
            status:[
               { label: "推广中", value: 1 },
               { label: "已结束", value: 2 },
            ],
            end_type:[
               { label: "有效期内", value: 1 },
               { label: "永久有效", value: 2 },
            ],
            pickerOptions: {
                disabledDate: (time) => {
                    return time.getTime() < new Date().getTime();
                },
            }
        }
    },
    watch: {
        findFormData: {
           handler(nval) {
                if (JSON.stringify(nval) != '{}') {
                    this.$nextTick(() => {
                        this.form = nval
                    })
                }
            },
            immediate: true,
            deep: false,
        },
    },
    methods: {
        // 取消按钮
        cancel() {
            this.$emit('editFormCancel')
        },

        submitForm() {
            this.$refs['form'].validate((valid, obj) => {
                if (valid) {
                    this.$emit('submitForm', this.form)
                }
            })
        },

        // 表单重置
        reset() {
            this.resetForm('form')
        }
    }
}
</script>
